<template>
	<div>
		<!-- :visible.sync="$store.state.mealflag" -->
		<el-dialog :close-on-click-modal="flag" :show-close="flag" title="订单信息" :visible.sync="$store.state.majorOrderInfoflag"
		 width="30%" center>
			<span>
				<!-- ////////////////////// -->
				<el-form ref="form" label-width="80px">
					<el-form-item label="订单id">
						<el-input v-model="majorOrder.majorid" maxlength=15 disabled></el-input>
					</el-form-item>
					<el-form-item label="套餐名称">
						<el-input v-model="majorOrder.majormealid.majormealremark" maxlength=15 disabled></el-input>
					</el-form-item>
					<el-form-item label="基本地址">
						<el-input v-model="majorOrder.u2id.u2baseaddress" style="width:40%" disabled></el-input>
					</el-form-item>
					<el-form-item label="详细地址">
						<el-input v-model="majorOrder.u2id.u2addressinfo" type="textarea" style="width:40%" disabled></el-input>
					</el-form-item>
					<el-form-item label="联系方式">
						<el-input v-model="majorOrder.u2id.u2phone" maxlength=15 disabled></el-input>
					</el-form-item>
					<el-form-item label="目标姓名">
						<el-input v-model="majorOrder.u2id.u2name" maxlength=15 disabled></el-input>
					</el-form-item>
					<!-- 	<el-form-item label="员工姓名">
						<el-input maxlength=15></el-input>
					</el-form-item> -->
					<el-form-item label="员工姓名">
						<el-select v-model="empval" placeholder="请选择">
							<el-option v-for="item in staffList" :key="item.empid" :label="item.empname" :value="item.empid">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="订单描述">
						<el-input type="textarea" v-model="majorOrder.majordetail" maxlength=55 disabled></el-input>
					</el-form-item>
				</el-form>
				<!-- ////////////////////// -->
			</span>
			<span slot="footer" class="dialog-footer">
				<el-button type="danger" @click="orderflag1(false)" :disabled="majorOrder.majorstate=='3'">结束服务</el-button>
				<el-button @click="mealflagcancel()">取 消</el-button>
				<el-button type="primary" @click="orderflag(false)" :disabled="majorOrder.majorstate!='1'">{{save}}</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		request
	} from "network/request.js"
	export default {
		props: {
			staffList: {},
			majorOrder: {
				"major0remark2": "string",
				"majorcreatetime": "2019-10-14T10:25:05.881Z",
				"majordetail": "string",
				"majorid": 0,
				"majormealid": 0,
				"majorprice": 0,
				"majorremark": "string",
				"majorstate": "string",
				"u2id": 0,
				"uid": 0
			}
		},
		data() {
			return {
				lab1: 1,
				lab2: 2,
				flag3: false,
				flag: false,
				flag2: true,
				mealstate2: "1",
				empval: "",
				save: "保存",
				emp: {}
			};
		},
		methods: {
			orderflag(flag) {
				if (this.empval == "") {
					this.save = "请选择员工"
				} else {
					request({
						url: '/Order/majorOrder',
						method: 'patch',
						data: {
							"major0remark2": this.majorOrder.major0remark2,
							"majorcreatetime": this.majorOrder.majorcreatetime,
							"majordetail": this.majorOrder.majordetail,
							"majorid": this.majorOrder.majorid,
							"majormealid": this.majorOrder.majormealid.majormealid,
							"majorprice": this.majorOrder.majorprice,
							"majorremark": this.majorOrder.majorremark,
							"majorstate": "2",
							"u2id": this.majorOrder.u2id.u2id,
							"uid": this.majorOrder.uid.uid
						}
					}).then(res => {

					})
					request({
						url: '/OrderEmp/majorinfo',
						method: 'post',
						data: {
							"empid": this.empval,
							"majorid": this.majorOrder.majorid,
							"majorinfoidid": 0,
							"majorremark": "string"
						}
					}).then(res => {
						return request({
							url: '/Emp/empInfo',
							method: 'get',
							params: {
								// id:this.$store.state.mealid
								"empid": this.empval,
							}
						})
					}).then(res => {
						this.emp = res.data
						return request({
							url: '/Emp/empInfo',
							method: 'patch',
							params: {
								// id:this.$store.state.mealid
								"empid": this.emp.empid,
								"empname": this.emp.empname,
								"empremark": this.emp.empremark,
								"empstate": "1",
								"emptype": this.emp.emptype
							}
						})
					}).then(res => {
						this.$store.commit("updateMajorOrderInfoflag", false)
						this.$router.push("blank_emt")
					})
				}
			},
			orderflag1(flag) {
				/*提醒用户是否删除*/
				this.$confirm('此操作将永久结束该订单服务, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					/*****************/
					if (this.majorOrder.majorstate == "1") {
						request({
							url: '/Order/majorOrder',
							method: 'patch',
							data: {
								"major0remark2": this.majorOrder.major0remark2,
								"majorcreatetime": this.majorOrder.majorcreatetime,
								"majordetail": this.majorOrder.majordetail,
								"majorid": this.majorOrder.majorid,
								"majormealid": this.majorOrder.majormealid.majormealid,
								"majorprice": this.majorOrder.majorprice,
								"majorremark": this.majorOrder.majorremark,
								"majorstate":"3",
								"u2id": this.majorOrder.u2id.u2id,
								"uid": this.majorOrder.uid.uid
							}
						}).then(res => {
							this.$store.commit("updateMajorOrderInfoflag", false)
							this.$router.push("blank_emt")
						})
					} else {
						request({
							url: '/Order/majorOrder',
							method: 'patch',
							data: {
								"major0remark2": this.majorOrder.major0remark2,
								"majorcreatetime": this.majorOrder.majorcreatetime,
								"majordetail": this.majorOrder.majordetail,
								"majorid": this.majorOrder.majorid,
								"majormealid": this.majorOrder.majormealid.majormealid,
								"majorprice": this.majorOrder.majorprice,
								"majorremark": this.majorOrder.majorremark,
								"majorstate": "3",
								"u2id": this.majorOrder.u2id.u2id,
								"uid": this.majorOrder.uid.uid
							}
						}).then(res => {
							this.$store.commit("updateMajorOrderInfoflag", false)
						})
						request({
							url: '/OrderEmp/majorinfoByMajorId',
							method: 'get',
							params: {
								// id:this.$store.state.mealid
								majorId:this.majorOrder.majorid
							}
						}).then(res => {

							return request({
								url: '/Emp/empInfo',
								method: 'get',
								params: {
									// id:this.$store.state.mealid
									empid: res.data.empid
								}
							})
						}).then(res => {
							return request({
								url: '/Emp/empInfo',
								method: 'patch',
								params: {
									// id:this.$store.state.mealid
									"empid": res.data.empid,
									"empname": res.data.empname,
									"empremark": res.data.empremark,
									"empstate": "2",
									"emptype": res.data.emptype
								}
							})
						}).then(res => {
							this.$store.commit("updateMajorOrderInfoflag", false)
							this.$router.push("blank_emt")
						})

					}

					/*****************/
					this.$message({
						type: 'success',
						message: '结束成功!'
					});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消结束'
					});
				});
			},
			mealflagcancel() {
				// this.$store.commit("updateOrderInfoflag", false)
				this.$store.commit("updateMajorOrderInfoflag", false)
			},
			onSubmit() {
				console.log('submit!');
			}
		}
	};
</script>

<style>
</style>
